<?php

namespace App\Http\Controllers\Admin;

use App\Model\OrderInfo;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Order;


class OrderController extends Controller
{
    const page =10;
    const view = 'admin.order';


    public function index(Request $request,Order $order){
            $like = $request->input('querystr',null);
            $status= $request->input('status',-1);
            $orderDetails = $order->OrderDetail($like,self::page,$status);
            $pam['order'] = $orderDetails;
            $pam['querystr'] = $like;
            $pam['status'] = $status;
        return view(self::view.'.order')->with($pam);
    }

    public function ChangeStatus(Request $request,order $order){
            $id = $request->input('id',null);
            $data['pay_status'] = $request->input('pay_status',null);
            $date['send_status'] = $request->input('send_status',null);
            $data['update_time'] = strtotime('now');
            $OrderChange = $order->where('id',$id)->update($data);
            if($OrderChange){
                return ApiResponse(['id'=>$id],'修改成功',1);
            }else{
                return ApiResponse([],'修改状态失败',0);
            }
    }

    public function GetStatus(Request $request,order $order){
        $id = $request->input('id');
        $pam['orderDetail'] = $order::find($id);
        return view(self::view.'.changeStatus')->with($pam);
    }

    public function GetOrderDetail(Request $request,order $order){
        $id = $request->input('id',null);
        $orderDetails = $order->OrderDetail(null,1,null,$id);
        $orderDetails = $orderDetails->toArray();
        if(!empty( $orderDetails)){
            return ApiResponse($orderDetails['data'][0],'查询成功',1);
        }else{
            return ApiResponse([],'该订单不存在',0);
        }
    }

}
